package net.maku.framework.mybatis.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.maku.framework.common.query.Query;

/**
 * mybatis plus 简化工具类
 *
 * @author hy
 * @version 1.0
 */
public class MBPUtils {


    /**
     * 构建page
     *
     * @param query 查询参数
     * @param clazz 泛型类型
     * @return Page
     */
    public static <T> IPage<T> buildPage(Query query, Class<T> clazz) {
        return new Page<>(query.getPage(), query.getLimit());
    }

    /**
     * 构建LambdaQueryChainWrapper
     *
     * @param entityClass 实体类型
     */
    public static <T> LambdaQueryChainWrapper<T> buildLQCWrapper(Class<T> entityClass, BaseMapper<T> mapper) {
        return new LambdaQueryChainWrapper<>(mapper, entityClass);
    }


    /**
     * 构建QueryWrapper
     *
     * @param entityClass 实体类型
     */
    public static <T> QueryWrapper<T> buildQWrapper(Class<T> entityClass) {
        return new QueryWrapper<>();
    }


    /**
     * 构建LambdaQueryWrapper
     *
     * @param entityClass 实体类型
     */
    public static <T> LambdaQueryWrapper<T> buildLQWrapper(Class<T> entityClass) {
        return new LambdaQueryWrapper<>(entityClass);
    }

}